﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SheepStorage.API.Application.Command.DepartmentCommand;
using SheepStorage.API.Application.Command.RoleManCommand;
using SheepStorage.API.Baseclass;
using SheepStorage.Domain.Entity;
using SheepStorage.Service.Interface;
using System.Data;

namespace SheepStorage.API.Controllers
{
    /// <summary>
    /// 角色模块
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class RolesController : ControllerBase
    {
        private readonly IRolesService rolesService;
        private readonly IMediator mediator;

        public RolesController(IRolesService rolesService, IMediator mediator)
        {
            this.rolesService = rolesService;
            this.mediator = mediator;
        }
        /// <summary>
        /// 查询所有角色
        /// </summary>
        /// <returns></returns>
        [HttpPost]
       
		public async Task<Results<List<Role>>> GetAllRoles(RoleShowCommand command)
		{
			return await mediator.Send(command);
		}
		/// <summary>
		/// 添加角色
		/// </summary>
		/// <param name="role"></param>
		/// <returns></returns>
		[HttpPost]
        public async Task< Results<int>> AddRole(Role role)
        {
            var res = await rolesService.AddRole(role);
            return Results<int>.DataResult(res);
        }

        /// <summary>
        /// 根据ID查看角色详细信息
        /// </summary>
        /// <param name="RoleId"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task< Results<Role>> GetAllRolesById(int RoleId)
        {
            var entity = await rolesService.GetAllRolesById(RoleId);
            return Results<Role>.DataResult(entity);
        }
        /// <summary>
        /// 逻辑删除角色信息
        /// </summary>
        /// <param name="RoleId"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task< Results<int>> DeleteRole(int RoleId)
        {
            var res = await rolesService.DeleteRole(RoleId);
            return Results<int>.DataResult(res);
        }
		/// <summary>
        /// 根据角色分配菜单权限  
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
	 
		[HttpPost]
		public async Task<Results<int>> AddMenuToRole(RoleToMenuCommand command)
		{
			return await mediator.Send(command);
		}

	}
}
